package com.cloud.cloudorder.order.config.rabbitmq;

import com.cloud.common.constant.RabbitmqOrderConstants;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author : Luojie
 * @CreateTime : 2019/9/3
 * @Description :
 **/
@Configuration
public class TopicRabbitConfig {

    //队列 起名：OrdeTopicQueue
    @Bean
    public Queue OrdeTopicQueue() {
        //true 是否持久
        return new Queue(RabbitmqOrderConstants.ORDER_TOPIC_QUEUE,true);
    }

    //Topic交换机 起名：TopicExchange
    @Bean
    TopicExchange OrderTopicExchange() {
        return new TopicExchange(RabbitmqOrderConstants.ORDER_TOPIC_EXCHANGE);
    }

    //绑定  将队列和交换机绑定, 并设置用于匹配键：topic.#
    @Bean
    Binding bindingTopic() {
        return BindingBuilder.bind(OrdeTopicQueue()).to(OrderTopicExchange()).with(RabbitmqOrderConstants.ORDER_TOPIC_ROUTING);
    }
}